import request from '../utils/request';

/**
 * 标签相关API
 */
const tagApi = {
  /**
   * 获取标签列表
   * @returns {Promise} - 标签列表结果
   */
  getTags: async () => {
    try {
      const response = await request.get('/admin/tags');
      return response;
    } catch (error) {
      console.error('获取标签列表失败:', error);
      throw error;
    }
  },
  
  /**
   * 添加标签
   * @param {Object} tag - 标签数据
   * @param {string} tag.name - 标签名称
   * @returns {Promise} - 添加结果
   */
  addTag: async (tag) => {
    try {
      const response = await request.post('/admin/tags', tag);
      return response;
    } catch (error) {
      console.error('添加标签失败:', error);
      throw error;
    }
  },
  
  /**
   * 更新标签
   * @param {number|string} id - 标签ID
   * @param {Object} tag - 标签数据
   * @returns {Promise} - 更新结果
   */
  updateTag: async (id, tag) => {
    try {
      const response = await request.put(`/admin/tags/${id}`, tag);
      return response;
    } catch (error) {
      console.error('更新标签失败:', error);
      throw error;
    }
  },
  
  /**
   * 删除标签
   * @param {number|string} id - 标签ID
   * @returns {Promise} - 删除结果
   */
  deleteTag: async (id) => {
    try {
      const response = await request.delete(`/admin/tags/${id}`);   
      return response;
    } catch (error) {
      console.error('删除标签失败:', error);
      throw error;
    }
  },
  

};

export default tagApi;
export { tagApi };
